﻿using System;
using System.Text;

namespace Catchbase.Service.API
{
    public sealed class SecurityManager : ISecurityManager
    {
        private readonly string _token;
        public SecurityManager(string email, string sharedSecret)
        {
            var text = string.Format("{0}:{1}", email, sharedSecret);
            var b64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(text.ToCharArray()));
            _token = "Basic " + b64;
        }

        public void SecureRequest(HttpWebRequestGateway request)
        {
            AddAuthorization(request);
        }

        private void AddAuthorization(HttpWebRequestGateway request)
        {
            request.Headers["Authorization"] = _token;
        }
    }
}